#ifndef CM_H
#define CM_H

#include <apr_time.h>
#include "mpi.h"
#include "oom.h"

#define CM_SUCCESS 0
#define CM_FAILURE 1

int CM_Init(int *listen_port);

int CM_Send(void *buf, int count, MPI_Datatype datatype, int source,
	int dest, int context, int tag, int dest_world_rank, MPI_Request *request);
	
int CM_Recv(void *buf, int count, MPI_Datatype datatype, int source, int dest,
	int context, int tag, MPI_Request *request);
	
int CM_SendAll(void *buf, int count, MPI_Datatype datatype, int source,
		       Comm *comm, Request **requests);
	
int CM_RecvAll(void *buf, int count, MPI_Datatype datatype, int dest,
	Comm *comm, Request **requests);
	
int CM_Wait(Request *request, int *source, int *tag, int *error);

int CM_Wait2(Request *request, MPI_Status *status);

int CM_Waitany(int count, Request **requests, int *index, MPI_Status *status);

int CM_Waitsome(int incount, Request **requests, int *outcount, int *indices,
	MPI_Status *statuses);

int CM_Test(Request *request, int *flag, int *source, int *tag, int *error);

int CM_Test2(Request *request, int *flag, MPI_Status *status);

int CM_Iprobe(int source, int dest, int context, int tag, int *flag,
	MPI_Status *status);
	
int CM_Probe(int source, int dest, int context, int tag, MPI_Status *status);

int CM_Start(Request *request);

int CM_Finalize();

#endif
